package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.CardInsertRequestDTO;
import com.example.child_protection.dto.request.find.CardRequestDTO;
import com.example.child_protection.dto.request.find.GetCardRequestDTO;
import com.example.child_protection.dto.response.CardListResponseDTO;
import com.example.child_protection.dto.response.CardResponseDTO;
import com.example.child_protection.service.CardManageService;
import com.example.child_protection.service.CardQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 儿保卡号管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("card")
@Api(value = "/api-card", description = "儿保卡号管理")
public class CardController extends BaseController {

    @Autowired
    public CardManageService cardManageService;

    @Autowired
    public CardQueryService cardQueryService;

    @ApiOperation(value ="获取新的儿保卡号", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/getCardNo", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CardResponseDTO getCardNo(GetCardRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        CardResponseDTO responseDTO = cardQueryService.getCardNo(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询儿保卡号列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CardListResponseDTO findList(CardRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        CardListResponseDTO responseDTO = cardQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除儿保卡号", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = cardManageService.delete(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="批量制卡", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/createCardBatch", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public CardListResponseDTO createCardBatch(CardInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        CardListResponseDTO responseDTO = cardManageService.createCardBatch(requestDTO);
        return responseDTO;
    }

}
